{% extends "catalog/base_generic.html" %}

{% block title %}作者列表{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="page-header mb-0">
        <i class="fas fa-user-edit me-2"></i>作者列表
    </h1>
    {% if perms.catalog.can_mark_returned %}
    <a href="{% url 'author-create' %}" class="btn btn-primary">
        <i class="fas fa-plus me-1"></i>添加作者
    </a>
    {% endif %}
</div>

<div class="row g-4">
    {% for author in author_list %}
    <div class="col-md-6">
        <div class="card h-100">
            <div class="card-body">
                <h5 class="card-title">{{ author.name }}</h5>
                <p class="card-text text-muted">
                    <i class="fas fa-birthday-cake me-1"></i>
                    {% if author.date_of_birth %}{{ author.date_of_birth|date:"Y年m月d日" }}{% else %}未知{% endif %}
                    {% if author.date_of_death %} - {{ author.date_of_death|date:"Y年m月d日" }}{% endif %}
                </p>
                <p class="card-text">{{ author.bio|truncatewords:30 }}</p>
                <div class="d-flex justify-content-between align-items-center">
                    <a href="{{ author.get_absolute_url }}" class="btn btn-sm btn-outline-primary">
                        <i class="fas fa-info-circle me-1"></i>查看详情
                    </a>
                    {% if perms.catalog.can_mark_returned %}
                    <div>
                        <a href="{% url 'author-update' author.pk %}" class="btn btn-sm btn-outline-secondary">
                            <i class="fas fa-edit me-1"></i>编辑
                        </a>
                        <a href="{% url 'author-delete' author.pk %}" class="btn btn-sm btn-outline-danger">
                            <i class="fas fa-trash me-1"></i>删除
                        </a>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
    {% empty %}
    <div class="col-12">
        <div class="alert alert-info" role="alert">
            <i class="fas fa-info-circle me-2"></i>暂无作者记录
        </div>
    </div>
    {% endfor %}
</div>

{% if is_paginated %}
<nav aria-label="分页导航" class="mt-4">
    <ul class="pagination justify-content-center">
        {% if page_obj.has_previous %}
        <li class="page-item">
            <a class="page-link" href="?page={{ page_obj.previous_page_number }}">
                <i class="fas fa-chevron-left"></i>
            </a>
        </li>
        {% endif %}
        
        {% for i in paginator.page_range %}
        <li class="page-item {% if page_obj.number == i %}active{% endif %}">
            <a class="page-link" href="?page={{ i }}">{{ i }}</a>
        </li>
        {% endfor %}
        
        {% if page_obj.has_next %}
        <li class="page-item">
            <a class="page-link" href="?page={{ page_obj.next_page_number }}">
                <i class="fas fa-chevron-right"></i>
            </a>
        </li>
        {% endif %}
    </ul>
</nav>
{% endif %}
{% endblock %} 